#!/usr/local/bin/thrift --java --php --py
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# *** PLEASE REMEMBER TO EDIT THE VERSION CONSTANT WHEN MAKING CHANGES ***
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#
# Interface definition for Cassandra Service
#

namespace java cn.edu.thu.laud.server.thrift

# Thrift.rb has a bug where top-level modules that include modules 
# with the same name are not properly referenced, so we can't do
# Cassandra::Cassandra::Client.


# The API version (NOT the product version), composed as a dot delimited
# string with major, minor, and patch level components.
#
#  - Major: Incremented for backward incompatible changes. An example would
#           be changes to the number or disposition of method arguments.
#  - Minor: Incremented for backward compatible changes. An example would
#           be the addition of a new (optional) method.
#  - Patch: Incremented for bug fixes. The patch level should be increased
#           for every edit that doesn't result in a change to major/minor.
#
# See the Semantic Versioning Specification (SemVer) http://semver.org.
#const string VERSION = "19.20.0"

include "interface/cassandra.thrift"
include "interface/hive_service.thrift"
#
# data structures
#

/** Basic unit of data within a ColumnFamily.
 * @param end_loc.  last name's  location.
 * @param last_name. 
 */
struct LaUDColumnLoc {
   1: optional binary  last_name,
   2: optional i32 last_loc
}

//struct ColumnLocation{
//1: string ks,
//2: string cf,
//3: binary col,
//4: binary rowkey
//}
/** fileInfo ,one is big stream ,the other is a bytes[]
 * @param info . big stream: when update ,it's local file path .when download ,it's null. bytes[]: null
 * @param checkcode . big stream: it's a check code.
 * @param direction . big stream : it's 'READ_FROM'(download) or 'WRITE_INTO'(upload). bytes[]: it's 'WRITE_INTO_CASSANDRA'.
 * @param columnLocation . big sream :null. bytes[]: column info.
 */
struct FileInfo{
	1:optional string info,
	2:optional string checkcode ,
	3:optional byte direction,
//	4: optional ColumnLocation colum_location
}


/**  result of Hive or Cassandra or LaSQL.
 * @param type.  0 is cassandra, 1 is LaSQL, 2 is Hive.
 * @param CqlResult. 
 */
struct LaUDResult {
   1: required  i16  type,
   2: optional cassandra.CqlResult cqlResult
   3: optional list<map<string,FileInfo>> fileInfos
}
exception LaUDServerException {
  1: string message
  2: i32 errorCode
  3: string SQLState
}

/**
  * Executes a LaSQL (LaUD Query Language) statement and returns a
  * LaSQLResult containing the results.
   */
service LaUD {   
	/**
	 * 
	 * @param key
	 * @param column_parent
	 * @param location the column location which you want to find 
	 * @param lastName the column's beginName.it will be the start position to find.
	 * @param lastLoc the column's beginLoc.it will be the start position to find.
	 * @param consistency_level
	 * @return
	 * @throws InvalidRequestException
	 * @throws UnavailableException
	 * @throws TimedOutException
	 */
  LaUDColumnLoc get_column_name(
  1: binary key,
  2: cassandra.ColumnParent column_parent,
  3:i32 location,
  4: binary lastName,
  5: i32 lastLoc,
  6: cassandra.ConsistencyLevel consistency_level)
	throws(
	1: cassandra.InvalidRequestException ie,
	2: cassandra.UnavailableException ue,
	3: cassandra.TimedOutException te)
 
 # Execute a query. Takes a HiveQL string
  void executeHiveQl(1:string query) throws(1:hive_service.HiveServerException ex)

	 # Execute a query. Takes a HiveQL or CQL or LaSQL string
  LaUDResult execute(1: binary query ,2:required cassandra.Compression compression)
throws (1:cassandra.InvalidRequestException ire,
            2:cassandra.UnavailableException ue,
            3:cassandra.TimedOutException te,
            4:cassandra.SchemaDisagreementException sde,
			5:hive_service.HiveServerException he,
			6:LaUDServerException le)

LaUDResult execute_with_parameters(1: binary query ,2:required cassandra.Compression compression,3:list<binary> parameters)
throws (1:cassandra.InvalidRequestException ire,
            2:cassandra.UnavailableException ue,
            3:cassandra.TimedOutException te,
            4:cassandra.SchemaDisagreementException sde,
			5:hive_service.HiveServerException he,
			6:LaUDServerException le)
 
    /**
   * Executes a CQL (Cassandra Query Language) statement and returns a
   * CqlResult containing the results.
   */
  cassandra.CqlResult executeCql(1:required binary query, 2:required cassandra.Compression compression)
    throws (1:cassandra.InvalidRequestException ire,
            2:cassandra.UnavailableException ue,
            3:cassandra.TimedOutException te,
            4:cassandra.SchemaDisagreementException sde)
        
  string get_laud_session_id() throws(1:LaUDServerException le )
	
 bool insert_into_kv(1: required string sessionId,2:required string checkcode,3:required binary insertdata) throws  (1:cassandra.InvalidRequestException ire,
            2:cassandra.UnavailableException ue,
            3:cassandra.TimedOutException te,
            4:cassandra.SchemaDisagreementException sde,
			5:hive_service.HiveServerException he,
			6:LaUDServerException le)

 binary get_from_kv(1: required string sessionId,2:required string checkcode)
 throws (1:cassandra.InvalidRequestException ire,
  2:cassandra.NotFoundException nfe, 
  3:cassandra.UnavailableException ue, 
  4:cassandra.TimedOutException te,
  5:LaUDServerException le)
}
